<template>
  <div>
    <el-dialog
      title="选择供应商"
      :visible.sync="dialogVisible"
      width="50%"
      :before-close="handleClose"
    >
      <el-row>
        <el-col :span="6" :offset="1">
          <el-input placeholder="请输入供应商名" >
            <el-button @click="search" slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="22" :offset="1">
          <el-table ref="supplyTable"
                    :data="suppliers"
                    highlight-current-row
                    @current-change="handleCurrentChange">
            <el-table-column label="供应商" prop="user.uname"></el-table-column>
            <el-table-column label="价格(元)"  prop="supplierPrice"> </el-table-column>
          </el-table>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="22" :offset="1">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleChange"
            :current-page="pageno"
            :page-sizes="[5, 10, 15, 20]"
            :page-size="pagesize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
          >
          </el-pagination>
        </el-col>
      </el-row>
    </el-dialog>
  </div>
</template>

<script>
  export default {
    name: "ShowSupply",
    data() {
      return {
        fromIndex:null,
        supply:{gId:null},
        suppliers:[],
        dialogVisible: false,//模态框状态
        pageno: 1,
        pagesize: 5,
        total: 1,
      }
    },
    methods:{
      handleCurrentChange(val) {
        //确认供应商
        this.$parent.addForm[this.fromIndex].supplyOrderId=val.id;
        this.$parent.addForm[this.fromIndex].supplierPrice = val.supplierPrice;
        this.$parent.addForm[this.fromIndex].supplyId = val.user.id;
        this.$parent.addForm[this.fromIndex].uname=val.user.uname;
        this.cancel();
      },
      getData(){
      //获取供应商以及价格
        var params = {}
        params["pageno"]=this.pageno;
        params["pagesize"]=this.pagesize;
        Object.keys(this.supply).forEach(item => {
          params[item]=this.supply[item];
        });
        this.$axios("supplierSupplyOfGoods/queryAllSupplier.action",{params:params})
          .then(res => {
            this.suppliers = res.data.records;
            this.total=res.data.total;
          })
          .catch(err => {
            this.$message.error(err)
          })
      },
      search(){
        this.getData();
      },
      handleSizeChange(val) {
        //每页范围
        this.pagesize = val;
        this.getData();
      },
      handleChange(val) {
        //当前页
        this.pageno = val;
        this.getData();
      },
      handleClose(done) {
        //模态框的关闭
        this.$confirm("确认关闭？")
          .then((_) => {
           this.cancel();
          })
          .catch((_) => {
          });
      },
      cancel(){
        this.fromIndex=null;
        this.supply.gId=null;
        this.dialogVisible=false;
      }
    }
  }
</script>

<style scoped>

</style>
